package LeetCode;

public class LC_517_SuperWashingMachines {

    public static void main(String[] args) {

    }

    class Solution {
        public int findMinMoves(int[] machines) {
            int n = machines.length;
            int sum = 0;
            for (int machine : machines) sum += machine;
            if (sum % n != 0)
                return -1;
            int avg = sum / n;
            int leftnum = 0;
            int minmove = 0;
            for (int machine : machines) {
                int cu = machine - avg;
                leftnum += cu;
                minmove = Math.max(minmove, Math.max(Math.abs(leftnum), cu));
            }
            return minmove;
        }
    }

}